package com.haha.project0301.config;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author dsx
 * @date 2021/3/3 9:16
 * @since JDK1.8
 */
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        Object logined = request.getSession().getAttribute("logined");
        if (logined == null){
            request.setAttribute("err","请登录后重试");
            request.getRequestDispatcher("index.html").forward(request,response);
            return false;//不放行
        }else {
            return true;//放行
        }
        
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
